package de.slothsoft.wasbinich.swingclient.common;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.RenderingHints;

import javax.swing.JPanel;

public class StrippedPanel extends JPanel {

    private static final long serialVersionUID = -1561145395461045296L;

    private Color firstColor;
    private Color secondColor;
    private int stripesWidth = 10;
    private boolean vertical = true;

    @Override
    public void paint(Graphics g) {
	Graphics2D g2 = (Graphics2D) g;
	g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

	if (this.firstColor != null && this.secondColor != null) {
	    paintStripes(g2);
	}
	printChildren(g2);
    }

    protected void paintStripes(Graphics2D g2) {
	Rectangle rect = g2.getClipBounds();
	g2.setPaint(this.firstColor);
	g2.fillRect(rect.x, rect.y, rect.width, rect.height);

	g2.setPaint(this.secondColor);
	for (int i = 0; i < rect.width; i += this.stripesWidth * 2) {
	    g2.fillRect(i, 0, this.stripesWidth, rect.height);
	}
    }

    public Color getFirstColor() {
	return this.firstColor;
    }

    public void setFirstColor(Color firstColor) {
	this.firstColor = firstColor;
    }

    public Color getSecondColor() {
	return this.secondColor;
    }

    public void setSecondColor(Color secondColor) {
	this.secondColor = secondColor;
    }

    public int getStripesWidth() {
	return this.stripesWidth;
    }

    public void setStripesWidth(int stripesWidth) {
	this.stripesWidth = stripesWidth;
    }

    public boolean isVertical() {
	return this.vertical;
    }

    public void setVertical(boolean vertical) {
	this.vertical = vertical;
    }

}
